package com.glela.order.mapper;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.ibatis.annotations.Param;

import com.glela.goods.model.GoodsCommission;
import com.glela.goods.model.LimitTimeSaleGoodsCommission;
import com.glela.goods.model.ShareGoods;
import com.glela.goods.model.TalentSerialGood;
import com.glela.goods.model.vo.InventoryVo;
import com.glela.order.model.OrderDetail;
import com.glela.order.model.OrderObject;
import com.glela.order.model.OrderSettlement;
import com.glela.order.vo.OrderDetailVo;
import com.glela.platform.model.response.ResponseUser;
import com.glela.platform.vo.GoodsSimpleVo;

public interface OrderDetailMapper {
	/**
	 * <dl>
	 * <dt>查询分时抢购用户已购数量</dt>
	 * </dl>
	 * @param userId 购买人id
	 * @param limitTimeSaleId 分时抢购ID
	 * @param productId 货品id
	 * @param inventoryId 库存ID
	 * @return Integer 购买数量
	 * @author zls
	 * @date 2017年7月24日 下午5:55:23
	 */
	Integer selectLimitSaleNums(@Param("userId")long userId, @Param("limitTimeSaleId")int limitTimeSaleId, @Param("productId")long productId, @Param("inventoryId")long inventoryId);

	int deleteByPrimaryKey(Long id);

	int insert(OrderDetail record);

	int insertSelective(OrderDetail record);

	OrderDetail selectByPrimaryKey(Long id);

	int updateByPrimaryKeySelective(OrderDetail record);

	int updateByPrimaryKey(OrderDetail record);

	OrderDetail selectByUserGoodApplywelfareId(@Param("userId") long userId, @Param("goodId") long goodId,
			@Param("applywelfareId") int applywelfareId,@Param("activityType") int activityType);

	public int subInventoryNumById(@Param("inventoryId") long inventoryId, @Param("quantity") int quantity);

	public int batchSubInventoryNumById(List<OrderDetail> orderDetails);

	public int batchInsert(List<OrderDetail> orderDetails);

	public List<InventoryVo> selectInventoryInId(@Param("inventoryIdSet") Set<Long> inventoryIdSet);

	public List<TalentSerialGood> selectTalentSerialGoodInId(List<GoodsSimpleVo> list);

	public List<ShareGoods> selectShareGoodsInId(List<GoodsSimpleVo> list);

	public List<GoodsCommission> selectGoodsCommissionListInGoodId(List<OrderDetail> orderDetailList);
	
	public List<LimitTimeSaleGoodsCommission> selectLimitTimeSaleGoodsCommissionListInGoodId(List<OrderDetail> orderDetailList);

	public List<ResponseUser> selectTalentIdAndUserReRoleInId(
			@Param("orderDetailList") List<OrderDetail> orderDetailList, @Param("user") ResponseUser user);

	/**
	 * <dl>
	 * <dt>根据身份ID查询用户及其角色信息</dt>
	 * </dl>
	 * @param personIdlist
	 * @return List<ResponseUser>
	 * @author zls
	 * @date 2017年7月27日 下午3:47:46
	 */
	public List<ResponseUser> selectUserRoleInPersonId(List<String> personIdlist);

	/**
	 * <dl>
	 * <dt>更新订单明细状态为交易成功</dt>
	 * <dd>订单明细状态为已完成</dd>
	 * </dl>
	 * @param orderObjectList item.id 交易单id
	 * @return int
	 * @author zls
	 */
	public int updateStatusInOrderObjectId(List<OrderObject> orderObjectList);

	public List<OrderDetailVo> selectOrderDetailByStatusOrderObjectSn(@Param("orderSn") String orderSn,
			@Param("status") Integer status);

	public int updateOrderDetailPayByOrderObjectId(long orderObjectId);

	/** MaoZeYao **/
	/**
	 * 修改父订单、子订单、订单详情的状态为售后中
	 * 
	 * @param id
	 * @return
	 */
	public int updateOrderDetailToRefund(@Param("oId") Long oId, @Param("iId") Long iId, @Param("dId") Long dId);

	/**
	 * 
	 * @param orderDetailId
	 * @return
	 */
	int updateOrderDetailToCommentSuccess(Long orderDetailId);

	/**
	 * 查询订单详情的数量根据子订单ID
	 * 
	 * @param orderInfoId
	 * @return
	 */
	int selectOrderDetailByOrderInfoId(Long orderInfoId);

	/**
	 * 根据子订单的ID查询订单详情的评价已完成的订单数量
	 * 
	 * @param orderInfoId
	 * @return
	 */
	int selectOrderDetailCommentCompliteByOrderInfoId(Long orderInfoId);

	/**
	 * 根据父订单ID查询订单详情 集合
	 * 
	 * @param id
	 * @return
	 */
	List<OrderDetail> selectOrderDetilByOrderObjectId(Long orderObjectId);

	/**
	 * 修改订单详情的状态
	 * @param status_old 之前状态（更新时的状态）
	 * @param status_now 现在状态（要更新的状态）
	 * @param id 明细ID
	 * @return 影响行数
	 */
	int updateOrderDetailStatusById(@Param("orderDetailId") Long orderDetailId, @Param("status_old") int status_old,@Param("status_now") int status_now, @Param("updateTime") String updateTime);

	/**
	 * 修改订单明细的状态为已完成
	 * 
	 * @param id
	 * @param status
	 * @param string
	 * @return
	 */
	int updateOrderDetailStatusByOrderObjectId(@Param("orderObjectId") Long orderObjectId, @Param("status") int status,
			@Param("updateTime") String updateTime);

	/**
	 * 根据父订单的状态修改订单详情的状态
	 * 
	 * @param orderObjectId
	 * @return
	 */
	int updateOrderDetailToCommentSuccessByOrderObjectId(Long orderObjectId);

	List<OrderDetail> selectOrderDetailEntityByOrderInfoId(Long orderInfoId);

	int updateOrderDetailCommentStatusInRedfund(Long orderObjectId);

	int updateOrderDetailStatusByOrderInfoId(@Param("orderInfoId") Long orderInfoId, @Param("status") int status,
			@Param("updateTime") String updateTime);

	/** MaoZeYao **/

	/**
	 * 根据子订单查询所有的订单详情
	 * 
	 * @author houmf
	 * @param orderInfoId
	 * @return
	 */
	public List<OrderDetail> selectOrderDetailByOrderInfoIdC(long orderInfoId);

	OrderDetail selectOrderDetailEntityBuId(Long orderDetailId);

	int selectOrderDetailIsRefundCountByInfoId(long orderInfoId);

	int selectOrderDetailCountByOrderInfoId(long orderInfoId);

	int updateOrderDetailRefundToOpen(Long orderDetailId);

	public List<Integer> sselectOrderDetailOrderIdByUserId(@Param("talentId") long talentId, @Param("page") int page,
			@Param("pageSize") int pageSize);

	public int selectOrderInfoIdByTalentId(long taltntId);

	public int selectSumTotalFeeByTalentId(long taltntId);

	public int selectOrderInfoIdByTalentIdSumTotalFee(long taltntId);

	int selectDetailGoodsType(long orderObjectId);
	
	public List<OrderDetail> disposeOrderSettlement();
	
	public List<OrderSettlement> selectOrderSettlement();

	List<Map<String,Object>> selectStoreOrderNumByOpenStoreUserId(Map<String, Object> queryMap);
}
